// pages/newArmor/newArmor.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    weaponList: [],
    activeNames: -1,
    pageState: true

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (decodeURIComponent(options.id) === "New Exotic Armor") {
      this.getArmorList("getNewExoticArmor")
    } else {
      this.getArmorList("getNewArmor")

    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  getArmorList(path) {
    var that = this
    wx.request({
      url: 'http://daxian.viphk.ngrok.org/api/' + path, //仅为示例，并非真实的接口地址
      data: {},
      header: {
        'content-type': 'application/json' // 默认值
      },
      success(res) {
        // console.log(res.data)
        that.setData({
          weaponList: res.data,
          pageState: false
        })
      }
    })
  },
  selectCollapse(event) {
    var i = this.data.activeNames
    var id = event.currentTarget.dataset.id
    if (i === id) {
      this.setData({
        activeNames: -1
      })
    } else {
      this.setData({
        activeNames: id
      })
    }
  },
  goToArmorInfo(e) {
    wx.navigateTo({
      url: '../armorInfo/armorInfo?id=' + encodeURIComponent(e.currentTarget.dataset.id)
    })
  }
})